package edu.cuit.canary.core.service.bean;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.cuit.canary.core.mapper.SysUserMapper;
import edu.cuit.canary.core.service.SysUserService;
import edu.cuit.canary.entity.dto.SysUserDto;
import edu.cuit.canary.entity.po.SysUser;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class SysUserServiceBean extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {

    @Override
    public Page<SysUser> list(SysUserDto parameter) {
        Page<SysUser> page = Page.of(parameter.getPageIndex(), parameter.getPageSize());
        var wrapper = new LambdaQueryWrapper<SysUser>();

        if(StringUtils.hasLength(parameter.getUsername()))
            wrapper.like(SysUser::getUsername, parameter.getUsername());

        if(StringUtils.hasLength(parameter.getRealName()))
            wrapper.like(SysUser::getRealName, parameter.getRealName());

        if(parameter.getStatus() != null)
            wrapper.eq(SysUser::getStatus, parameter.getStatus());


        page = this.getBaseMapper().selectPage(page, wrapper);

        return page;
    }
}
